"use strict";
const { Model, Sequelize } = require("sequelize");
module.exports = (sequelize, DataTypes) => {
  class Shop extends Model {
    //采购模型
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      // Shop.belongsTo(models.Product,{
      //   foreignKey:'product_id'
      // })
      Shop.belongsTo(models.Contract, {
        foreignKey: "contract_id",
        allowNull: true,
      });
      Shop.belongsTo(models.Staff, {
        foreignKey: "purchaser_id",
        as: "purchaser",
        allowNull: true,
      });
      Shop.belongsTo(models.Staff, {
        foreignKey: "checker_id",
        as: "checker",
        allowNull: true,
      });
      Shop.hasOne(models.Service, {
        foreignKey: "shop_id",
      });

      // define association here
    }
  }
  Shop.init(
    {
      date_start: {
        type: DataTypes.DATEONLY,
        defaultValue: Sequelize.NOW,
      },
      date_end: {
        type: DataTypes.DATEONLY,
        defaultValue: Sequelize.NOW,
      }, //采购开始时间
      shop_status: DataTypes.STRING, //采购状态
      approval_status: {
        type: DataTypes.STRING,
        defaultValue: "待审核",
      }, //审核状态
      check_sug: DataTypes.STRING,
      // check_staffs:DataTypes.TEXT,
      products: DataTypes.TEXT, //{"5":3,"1":2}这种形式
      money: DataTypes.FLOAT(2),
    },
    {
      sequelize,
      modelName: "Shop",
      tableName: "shops",
    }
  );
  return Shop;
};
